% Load the Ground Truth in corresponding posture (vertices, triangles, vSignature, distanceMtr)

nV = size(vertices, 1);
nT = size(triangles, 1);

% Load results of the Blend Map
disp('--> (1) Load Blend Map Result');
% VarName1 - vi2tri
if( exist('VarName1', 'var') )
    vi2tri = VarName1; clear VarName1;
end % if

% Baricentric coordinates of vi2tri matching
if( exist('VarName2', 'var') )
    baricentric = zeros(nV, 3);
    % VarName2 - bar. coord. x
    baricentric(:, 1) = VarName2; clear VarName2;
    % VarName3 - bar. coord. y
    baricentric(:, 2) = VarName3; clear VarName3;
    % VarName4 - bar. coord. z
    baricentric(:, 3) = VarName4; clear VarName4;
end % if

% Prepare data structures

% Compare with Blend Map to Ground Truth
% AveErr = zeros(nV, 1);
% MaxErr = zeros(nV, 1);
Err = zeros(nV, 1);
for vi = 1 : nV
    groundTruth = vertices(vi, :)';
    
    % Corresponding triangle 
    tri = triangles( vi2tri(vi), : );
    V = zeros(3);
    V = vertices(tri, :)';
    bar = baricentric(vi, :)';
    blendMapCorr = V * bar;
    
    % Compute Euclidean norm / Geodesic could be an option
    Err(vi) = norm( groundTruth - blendMapCorr );
end % for

AveErr = mean(Err);
MaxErr = max(Err);

% Normalize error values by square root of mesh area
meshArea = triMeshArea(vertices, triangles);
AveErr = AveErr / sqrt(meshArea)
MaxErr = MaxErr / sqrt(meshArea)

% Export results and color maps
